<template>
	<view class="u-page">
		<view class="u-login-block">
			<u-row customStyle="margin-bottom: 10px">
				<u-col span="1">
					<view></view>
				</u-col>
				<u-col span="10">
					<view>
						<u--form labelPosition="left" ref="form1" :model="userInfo" :rules="rules">
							<u-form-item label="账号" prop="userInfo.username" borderBottom ref="item1">
								<u--input border="none"></u--input>
							</u-form-item>
							<u-form-item label="密码" prop="userInfo.password" borderBottom ref="item1">
								<u--input border="none"></u--input>
							</u-form-item>
							<u-button type="primary" text="登录" @click="login"></u-button>
							<u--text type="info" text="还没有账号？去注册" align="center" @clcik="register"></u--text>
						</u--form>
					</view>
				</u-col>
				<u-col span="1">
					<view></view>
				</u-col>
			</u-row>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {
					username: '',
					password: ''
				},
				rules: {
					'userInfo.username': {
						type: 'string',
						required: true,
						message: '请输入用户名',
						trigger: ['blur', 'change']
					},
					'userInfo.password': {
						type: 'string',
						min: 5,
						required: true,
						message: '请输入密码',
						trigger: ['blur', 'change']
					}
				}
			}
		},
		methods: {
			login() {
				this.$refs.form1.validate().then(res => {
					uni.$u.toast('校验通过')
					try {
						uni.setStorageSync('token_key', 'myToken');
						uni.switchTab({
							url: uni.getStorageSync("preurl")
						})
					} catch (e) {

					}
				}).catch(errors => {
					uni.$u.toast('校验失败')
				})

			},
			register() {
				uni.navigateTo({
					url: '/pages/register/register'
				});
			}
		}
	}
</script>

<style lang="scss">

</style>
